home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / IBPalettes / WW3DKit / RIBOpacity.m < prev    next >
Encoding:
Text File  |  1995-03-22  |  3.4 KB  |  163 lines

  1. // copyright 1993 Michael B. Johnson; some portions copyright 1994, MIT
  2. // see COPYRIGHT for reuse legalities
  3. //
  4.  
  5.  
  6. #import "RIBOpacity.h"
  7.  
  8. @implementation RIBOpacity
  9.  
  10. + initialize { return [RIBOpacity setVersion:1], self; }
  11.  
  12. - init
  13. {
  14.   [super init];
  15.   opacity[0] = 1.0;
  16.   opacity[1] = 1.0;
  17.   opacity[2] = 1.0;
  18.  
  19.   return self;
  20. }
  21.  
  22. - setOpacity:(RtColor)newOpacity
  23. {
  24.   opacity[0] = newOpacity[0];
  25.   opacity[1] = newOpacity[1];
  26.   opacity[2] = newOpacity[2];
  27.   return self;
  28. }
  29.  
  30. - getOpacity:(RtColor *)opacityContainer
  31. {
  32.   (*opacityContainer)[0] = opacity[0];
  33.   (*opacityContainer)[1] = opacity[1];
  34.   (*opacityContainer)[2] = opacity[2];
  35.   return self;
  36. }
  37.  
  38. - (RtColor *)opacity {  return &opacity; }
  39.  
  40. - (BOOL)theSameAs:otherRIBCommand
  41. {
  42.   RtColor  *otherOpacityPtr;
  43.  
  44.  
  45.   otherOpacityPtr = [otherRIBCommand opacity];
  46.   if ((*otherOpacityPtr)[0] != opacity[0])
  47.   {  return NO;
  48.   }
  49.   if ((*otherOpacityPtr)[1] != opacity[1])
  50.   {  return NO;
  51.   }
  52.   if ((*otherOpacityPtr)[2] != opacity[2])
  53.   {  return NO;
  54.   }
  55.  
  56.   return [super theSameAs:otherRIBCommand];
  57. }
  58.  
  59. - renderSelf:(WW3DCamera *)camera  startingAt:(RtFloat)shutterOpenTime endingAt:(RtFloat)shutterCloseTime
  60. {
  61.   RiOpacity(opacity);
  62.  
  63.   return self;
  64. }
  65.  
  66. // In prman 3.4, shading parameters don't motion blur...
  67. //- (BOOL)isMotionBlurrable { return YES; }
  68.  
  69. - (BOOL)isLerpable { return YES; }
  70.  
  71. // note: because we've made the WWSampleList "safe" for having
  72. // multiple samples with the same data, it's perfectly valid to return
  73. // yourself or b
  74. - lerpWith:b by:(float)uValue
  75. {
  76.    id       newMe = nil;
  77.    RtColor  aColor, bColor, newColor;
  78.  
  79.  
  80.    if (([self class] != [b class]) || (uValue <= 0.0))
  81.    {  return self;
  82.    }
  83.  
  84.    if (uValue >= 1.0)
  85.    {  return b;
  86.    }
  87.  
  88.    newMe = [super lerpWith:b by:uValue]; // this makes a copy for us
  89.  
  90.    // okay, now do the specific stuff for this class
  91.    [self getOpacity:&aColor];
  92.    [b getOpacity:&bColor];
  93.    newColor[0] = aColor[0] + ((bColor[0] - aColor[0]) * uValue);
  94.    newColor[1] = aColor[1] + ((bColor[1] - aColor[1]) * uValue);
  95.    newColor[2] = aColor[2] + ((bColor[2] - aColor[2]) * uValue);
  96.    [newMe setOpacity:newColor];
  97.  
  98.    return newMe;
  99. }
  100.  
  101.  
  102. - lerpSelfWith:b by:(float)uValue
  103. {
  104.    id       newMe = nil;
  105.    RtColor  aColor, bColor, newColor;
  106.  
  107.  
  108.    if (([self class] != [b class]) || (uValue <= 0.0))
  109.    {  return self;
  110.    }
  111.  
  112.    if (uValue >= 1.0)
  113.    {  return b;
  114.    }
  115.  
  116.    [super lerpSelfWith:b by:uValue]; // this makes a copy for us
  117.  
  118.    // okay, now do the specific stuff for this class
  119.    [self getOpacity:&aColor];
  120.    [b getOpacity:&bColor];
  121.    newColor[0] = aColor[0] + ((bColor[0] - aColor[0]) * uValue);
  122.    newColor[1] = aColor[1] + ((bColor[1] - aColor[1]) * uValue);
  123.    newColor[2] = aColor[2] + ((bColor[2] - aColor[2]) * uValue);
  124.    [newMe setOpacity:newColor];
  125.  
  126.    return self;
  127. }
  128.  
  129. - writeEve:(NXStream *)stream atTabLevel:(int)tab
  130. {
  131.    int  i;
  132.  
  133.  
  134.    for (i = 0; i < tab; i++)
  135.    {  NXPrintf(stream, "\t");
  136.    }
  137.    NXPrintf(stream, "Opacity {%f %f %f};", opacity[0], opacity[1], opacity[2]); 
  138.    return self;
  139. }
  140.  
  141. - read:(NXTypedStream*)stream 
  142. {
  143.     int version;
  144.     
  145.     [super read:stream];
  146.     version = NXTypedStreamClassVersion(stream,"RIBOpacity");
  147.     if (version == 0) NXReadTypes(stream,"i",&version), version=1;
  148.     if (version == 1) {
  149.     NXReadArray(stream, "f", 3, opacity);
  150.     } else {
  151.     }
  152.     return self;
  153. }
  154.  
  155. - write:(NXTypedStream*)stream 
  156. {
  157.     [super write:stream];
  158.     NXReadArray(stream, "f", 3, opacity);
  159.     return self;
  160. }
  161.  
  162. @end
  163.